"use client";
import LLayout from "@/components/layout/layout";
import { useCustomFetch } from "@/utils/network";
import { useEffect, useState } from "react";

export default function Information({ params }: any) {
  const [fileData, setFileData] = useState([]);
  function GetDataInfo(locale: string) {
    useCustomFetch(`/file?lng=${locale}`).then((res) => {
      setFileData(res.data);
    });
  }
  useEffect(() => {
    GetDataInfo(params.locale);
  }, [params]);
  return (
   <LLayout    locale={params.locale}     title="homeTitle">

<div className="flex flex-wrap text-xl">
      {[
        {
          name: "说明书/PDF/...资料下载",
          type: "instruction",
        },
        {
          name: "图纸资料下载",
          type: "drawing",
        },
        {
          name: "软件资料下载",
          type: "software",
        },
      ].map((itemx) => {
        return (
          <div key={itemx.name} className="px-4 mb-4 sm:w-full md:w-1/2">
            <section className="border-2 p-4">
              <h1 className=" font-semibold text-[#2563eb]">{itemx.name}</h1>
              <ul className="flex flex-col">
                {fileData
                  .filter((item: any) => item.filetype === itemx.type)
                  .map((itemy: any) => {
                    return (
                      <li
                        className="py-2 flex justify-between hover-bottom-line"
                        key={itemy.ID}
                      >
                        <span className="font-bold">
                          {itemy.filename.split(".")[0]}
                        </span>
                        <span>
                          <a
                            href={itemy.url}
                            className=" mr-4 text-2xl hover:text-green-500"
                            target="_blank"
                          >
                            查看
                          </a>
                          <a
                            href={itemy.url + "?down=" + new Date().getTime()}
                            className=" text-2xl hover:text-green-500"
                            target="_blank"
                          >
                            下载
                          </a>
                        </span>
                      </li>
                    );
                  })}
              </ul>
            </section>
          </div>
        );
      })}
    </div>

   </LLayout>
  );
}
